import React, { useEffect, useState } from 'react';
import { connect } from 'dva';

import styles from './IndexPage.css';
import { getList } from '../services/example'

function IndexPage(props) {
  const [msg, setMsg] = useState('nihao')

  // const dispatch = useDispatch();
  const { dispatch, list } = props;
  console.log('list:', props)

  useEffect(() => {
    // getList().then(res => {
    //   console.log('res: ',res)
    // })
  }, [])

  return (
    <div className={styles.normal}>
      <h1>DVA</h1>

      <h2 onClick={() => {
        dispatch({
          type: 'example/getList',
          payload: { page: 2, size: 5 }
        })
        .then(res => {
          console.log('res:', res)
        })
      }}>{msg}</h2>
    </div>
  );
}

export default connect((state) => {
  console.log('state:', state)
  return {...state}
},
 (dispatch) => {
   return { dispatch }
 })(IndexPage)
